faApp.controller('RoleListCtrl',['$scope','authService','$location','$controller','$route',function($scope,authService,$location,$controller,$route) {   
	$controller('BaseCtrl', {$scope: $scope}); 

  $scope.list = [];
  $scope.loading = true;

	$scope.$watch('config',function(){
    authService.roleList($scope.config).then(function(json){
      $scope.list = json.allGroup;
      $scope.pager = json.pager;
      $scope.loading = false;
    }); 
  },true)  
	$scope.config = {
		"pageSize" : 20,
		"pageNo" : 1
	};
  
	$scope.pageChanged = function(){
		$scope.config.pageNo = $scope.pager.pageNo;
	};

	$scope.linkDelete = function(id){
    authService.linkDelete({id:id}).then(function(json){
      $route.reload();    
    });
	}; 
}]);

faApp.controller('RoleAddCtrl',['$scope','authService','$location','$controller','$timeout',function($scope,authService,$location,$controller,$timeout) {   
	$controller('BaseCtrl', {$scope: $scope}); 

  $scope.item = {};
  $scope.allActions = {};
  $scope.selectActions = [];
  $scope.loading = true; 

  authService.urlList({}).then(function(json){
    $scope.actionList = json.actionList;
  });

	$scope.save = function(){
    if (!$scope.form.$invalid){ 
      var flag = false;
      for (var i in $scope.allActions){
        if ($scope.allActions[i]){
          flag = true;
          $scope.selectActions.push(i);
        }
      } 

      $scope.item['actionId'] = $scope.selectActions.join(",");
      authService.roleAdd($scope.item).then(function(json){
        if (json.statusCode){
          alert(json.statusCode);
        }else{
          $location.path("/role/list");
        }
      });
    }else{
      alert("请先完整填写表单");
    }
  };
 
}]);

faApp.controller('RoleEditCtrl',['$scope','authService','$location','$controller','$routeParams','$filter',function($scope,authService,$location,$controller,$routeParams,$filter) {   
	$controller('BaseCtrl', {$scope: $scope}); 

  $scope.item = {};
  $scope.allActions = {};
  $scope.selectActions = [];
  $scope.loading = true; 
  $scope.id = $routeParams.id; 

  authService.urlList({}).then(function(json){
    $scope.actionList = json.actionList;
  });

  authService.roleQuery($scope.id).then(function(json){
    $scope.item = json.groupInfo;
    angular.forEach(json.accessForGroup,function(o){
      $scope.allActions[o.actionId] = true;  
    });
  });

	$scope.save = function(){
    if (!$scope.form.$invalid){ 
      var flag = false;
      for (var i in $scope.allActions){
        if ($scope.allActions[i]){
          flag = true;
          $scope.selectActions.push(i);
        }
      } 

      $scope.item['actionId'] = $scope.selectActions.join(",");
      authService.roleEdit($scope.item).then(function(json){
        if (json.statusCode){
          alert(json.statusCode);
        }else{
          $location.path("/role/list");
        }
      });
    }else{
      alert("请先完整填写表单");
    }
  };
 
}]);

faApp.controller('UrlListCtrl',['$scope','authService','$location','$controller','$route',function($scope,authService,$location,$controller,$route) {   
	$controller('BaseCtrl', {$scope: $scope}); 

  $scope.list = [];
  $scope.loading = true;

	$scope.$watch('config',function(){
    authService.urlList($scope.config).then(function(json){
      $scope.list = json.actionList;
      $scope.pager = json.pager;
      $scope.loading = false;
    });
  },true)

	$scope.config = {
		"pageSize" : 20,
		"pageNo" : 1
	};
  
	$scope.pageChanged = function(){
		$scope.config.pageNo = $scope.pager.pageNo;
	};

	$scope.linkDelete = function(id){
    authService.linkDelete({id:id}).then(function(json){
      $route.reload();    
    });
	}; 
}]);

faApp.controller('UrlAddCtrl',['$scope','authService','$location','$controller','$timeout',function($scope,authService,$location,$controller,$timeout) {   
	$controller('BaseCtrl', {$scope: $scope}); 

  $scope.item = {};
  $scope.loading = true; 

	$scope.save = function(){
    if (!$scope.form.$invalid){ 

      authService.urlAdd($scope.item).then(function(json){
        if (json.statusCode){
          alert(json.statusCode);
        }else{
          $location.path("/url/list");
        }
      });
    }else{
      alert("请先完整填写表单");
    }
  };
 
}]);
  



